﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YWTSSys.BLL;
using YWTSSys.Library;
using YWTSSys.Model;

namespace YWTSSys.Web.MachineSys.YWTSWeb.yw
{
    public partial class MyTelRecordMasterList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "MyTelRecordMasterList";
            }
        }

        #region 属性 (查询条件)

        protected string sqlvalue
        {
            get
            {
                return GetRequestValue<string>("sqlvalue", "");

            }
        }
        /// <summary>
        /// 按日期 查看
        /// </summary>
        protected int viewteldate
        {
            get
            {
                return GetRequestValue<int>("viewteldate", -1);

            }
        }


        private string StartDate
        {
            get
            {
                return DateTime.Now.AddDays(viewteldate).ToString("yyyy-MM-dd 00:00:00");
            }
        }

        private string EndDate
        {
            get
            { 
                if(viewteldate<=-7)
                    return DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
                else
                    return DateTime.Now.AddDays(viewteldate).ToString("yyyy-MM-dd 23:59:59");
            }
        }


        /// <summary>
        /// 当前排序字段
        /// </summary>
        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "通话时间" : base.orderField;
            }
        }
        /// <summary>
        /// 当前排序方式
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "Desc" : base.orderDirection;
            }
        }
        #endregion



        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
            // this.AddLog(Permission.查看, GetSql());
        }

        protected void DataBind()
        {

            this.rpTelMenu.DataSource = TelRecordController.GetPagination(GetSql(), pageNum, numPerPage, SQLSort, ref TotalCount);
            this.rpTelMenu.DataBind();
          
        }

        protected string GetSql()
        {
             string wheresql = string.Format(" UserId={0} ", User.UserId);

            string ItemCodeSQL = "";
            if (!string.IsNullOrEmpty(sqlvalue))
            {
                ItemCodeSQL = string.Format(" 客户名称 like '%{0}%' or 手机号码 like '%{0}%' or 会员卡号 like '%{0}%' ", sqlvalue);
                wheresql=wheresql+" and ("+ItemCodeSQL+")";
            }

            string dateSQL = "";
            dateSQL = string.Format(" 通话时间 between '{0}' and '{1}' ", StartDate,EndDate);

            wheresql = wheresql + " and (" + dateSQL + ")";

            return wheresql;
        }
    }
}